<%@page import="csci5828.tasks.RequestId"%>
<%
RequestId requestId = (RequestId)request.getAttribute("requestId");
java.util.Date date = new java.util.Date(); 
%>
<html>
  <head>
    <title>Comet Reviews</title>
    <script type="text/javascript" src="scripts/prototype.js"></script>
    <script type="text/javascript" src="scripts/util.js"></script>
    <script type="text/javascript">
function handleResponse() {
	if (xmlhttp.readyState == 4) {
        var response = xmlhttp.responseText;
        var pattern = /^(.*)@END@.*$/m;
        if (response.match(pattern)) {
			response = response.replace(pattern, "$1");
        	$("results").innerHTML = response;
        	return;
        }
       	$("results").innerHTML = response;
       	xmlhttp.abort();
      	sendXmlHttpRequest();
	}
}

function sendXmlHttpRequest() {
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.open("GET", "waittaskresults?requestId=<%=requestId.getId()%>");
    xmlhttp.send(null);
}
    
window.onload = function() {
	xmlhttp = createXMLHttpRequest();
	sendXmlHttpRequest();
};
    </script>
  </head>
  <body>
    <h1>Search Reviews</h1>
    <form action="/cometreviews/waittask">
      <input type="text" name="query" size="100"/>
      <input type="submit"/>
    </form>
    
    <h1>Results</h1>
    Time is now: <%=date%>
    RequestId is <%=requestId%>
    <div id="results">
    </div>
  </body>
</html>